package company.managedbean;

import company.entity.Company;
import java.io.IOException;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;

@ManagedBean
@ViewScoped
public class CreateNewResultManagedBean implements Serializable {

    private Company company;
    private String message;

    public CreateNewResultManagedBean() {
    }

    public void initView(PhaseEvent event) {
        if (company == null) {
            company = (Company) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("newCompany");
        }
        message = "New company has been created. ID: "+String.valueOf(company.getId());
    }
    
    public void goBack() throws IOException{
        FacesContext.getCurrentInstance().getExternalContext().redirect("./companyManagement.xhtml");
    }

    public Company getCompany() {
        return company;
    }

    public void setCompany(Company company) {
        this.company = company;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
